package com.example.mvp.adapter;

import android.content.Context;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

public class BaseViewHolder extends RecyclerView.ViewHolder {
    private View rootView;
    private SparseArray<View> sparseArray;

    private Context context;

   public void setContext(Context context){
       this.context=context;
   }

    public BaseViewHolder(@NonNull View itemView) {
        super(itemView);
        rootView=itemView;
        sparseArray=new SparseArray<>();
    }
    
    public <T extends View> T getView(int viewId){
        if (sparseArray.get(viewId)==null){
            View viewById = rootView.findViewById(viewId);
            sparseArray.put(viewId,viewById);
        }
        return (T) sparseArray.get(viewId);
    }




    public void setText(int textViewId,String text){
        TextView textView = getView(textViewId);
        textView.setText(text);


    }
    public void setImage(int imageId, String image){
        ImageView view = getView(imageId);
        Glide.with(context).load(image).into(view);

    }
}
